package com.ruoyi.project.yingyu.activityReg.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.ruoyi.common.utils.MoneyUtil;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.framework.datasource.DynamicDataSourceContextHolder;
import com.ruoyi.project.user.kkuser.domain.KKUser;
import com.ruoyi.project.user.kkuser.mapper.KKUserMapper;
import com.ruoyi.project.user.kkuser.service.IKKUserService;
import com.ruoyi.project.yingyu.activityReg.domain.ActivityReg;
import com.ruoyi.project.yingyu.activityReg.mapper.ActivityRegMapper;
import com.ruoyi.project.yingyu.activityReg.service.IActivityRegService;

/**
 * 活动报名表Service业务层处理
 * 
 * @author ruoyi
 * @date 2019-12-02
 */
@Service
public class ActivityRegServiceImpl implements IActivityRegService {

	@Autowired
	private ActivityRegMapper activityRegMapper;

	@Autowired
	private IKKUserService kkUserService;

	/**
	 * 查询活动报名表
	 * 
	 * @param id 活动报名表ID
	 * @return 活动报名表
	 */
	@Override
	public ActivityReg selectActivityRegById(Long id) {
		return activityRegMapper.selectActivityRegById(id);
	}

	/**
	 * 查询活动报名表列表
	 * 
	 * @param activityReg 活动报名表
	 * @return 活动报名表
	 */
	@Override
	public List<ActivityReg> selectActivityRegList(ActivityReg activityReg) {
		List<ActivityReg> list = activityRegMapper.selectActivityRegList(activityReg);
		for (ActivityReg reg : list) {
			KKUser search = new KKUser();
			search.setAppId("yingyuword");
			search.setKkid(reg.getKkid());
			List<KKUser> users = kkUserService.selectKKUserList(search);
			if (!CollectionUtils.isEmpty(users)) {
				reg.setUser(users.get(0));
			}
			reg.setYuan(MoneyUtil.fee2yuan(reg.getTotalFee()).toString());
			System.out.println(reg.getYuan());
		}
		return list;
	}

	/**
	 * 新增活动报名表
	 * 
	 * @param activityReg 活动报名表
	 * @return 结果
	 */
	@Override
	public int insertActivityReg(ActivityReg activityReg) {
		return activityRegMapper.insertActivityReg(activityReg);
	}

	/**
	 * 修改活动报名表
	 * 
	 * @param activityReg 活动报名表
	 * @return 结果
	 */
	@Override
	public int updateActivityReg(ActivityReg activityReg) {
		return activityRegMapper.updateActivityReg(activityReg);
	}

	/**
	 * 删除活动报名表对象
	 * 
	 * @param ids 需要删除的数据ID
	 * @return 结果
	 */
	@Override
	public int deleteActivityRegByIds(String ids) {
		return activityRegMapper.deleteActivityRegByIds(Convert.toStrArray(ids));
	}

	/**
	 * 删除活动报名表信息
	 * 
	 * @param id 活动报名表ID
	 * @return 结果
	 */
	@Override
	public int deleteActivityRegById(Long id) {
		return activityRegMapper.deleteActivityRegById(id);
	}
}
